/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 */

import { IncrementalTask } from '../external/task/incremental-task.js';
import { FsOptions } from '../internal/snapshot/util/file-set.js';

import { IncrementalDecoratorType } from './types.js';
import { getSelfDeclaratorContainer, setSelfDeclaratorContainer } from './util.js';

type IncrementalDecorator = (target: IncrementalTask, propertyKey: string) => void;

/**
 * 用于生成Input/Inputs/IgnoreSuperIncremental装饰器
 * @param declaratorType
 */
export const createBaseDecorator = (declaratorType: IncrementalDecoratorType): (() => IncrementalDecorator) => {
  return () => {
    return (target: IncrementalTask, propertyKey: string) => {
      setSelfDeclaratorContainer(target);
      getSelfDeclaratorContainer(target)!.push({ propertyKey, declaratorType });
    };
  };
};

/**
 * 用于生成InputFile/InputFiles/OutputFile/OutputFiles装饰器
 * @param declaratorType
 */
export const createFileDecorator = (declaratorType: IncrementalDecoratorType): ((options?: FsOptions) => IncrementalDecorator) => {
  return (options?: FsOptions) => {
    return (target: IncrementalTask, propertyKey: string) => {
      setSelfDeclaratorContainer(target);
      getSelfDeclaratorContainer(target)!.push({ propertyKey, declaratorType, options });
    };
  };
};
